package com.jwttest.jwt.service;

import com.jwttest.jwt.dao.UserDao;
import com.jwttest.jwt.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * author: MaHX
 * date: 2019/10/28/23:23
 * description:
 **/
@Service
public class UserService implements UserDetailsService {
    @Autowired
    public UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = userDao.loadUserByUsername(s);
        if (user == null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return user;
    }
}
